﻿<Window x:Class="FlagEnum.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:System="clr-namespace:System;assembly=mscorlib" 
        xmlns:local="clr-namespace:FlagEnum"       
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style x:Key="VerticalSlideCheckBoxStyle" TargetType="{x:Type CheckBox}">
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="Padding" Value="2"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type CheckBox}">
                        <Border BorderThickness="1" Height="Auto" Width="Auto" CornerRadius="2" Margin="0" BorderBrush="Black">
                            <StackPanel>
                                <Border x:Name="PART_UPC"  Height="Auto" Width="Auto" CornerRadius="2" Margin="1.3" Padding="5,2">
                                    <TextBlock Text="上部分" FontSize="12" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                </Border>
                                <Border x:Name="PART_DWC" Height="Auto" Width="Auto" CornerRadius="2" Margin="1.3" Padding="5,2">
                                    <TextBlock Text="下部分" FontSize="12" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                </Border>
                            </StackPanel>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter TargetName="PART_UPC" Property="Background" Value="#997CFC00"/>
                            </Trigger>
                            <Trigger Property="IsChecked" Value="False">
                                <Setter TargetName="PART_DWC" Property="Background" Value="#997CFC00"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="HorizontalSlideCheckBoxStyle" TargetType="{x:Type CheckBox}">
            <Setter Property="Height" Value="18"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="FontWeight" Value="Bold"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type CheckBox}">
                        <Border x:Name="ForegroundPanel" CornerRadius="2" BorderBrush="Black" BorderThickness="1" Padding="0">
                            <DockPanel>
                                
                                <TextBlock x:Name="Content" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2,0" />
                                
                                <Border x:Name="CheckFlag" HorizontalAlignment="Right" VerticalAlignment="Center" CornerRadius="2" BorderThickness="0" Width="18" Height="16"/>

                                <TextBlock x:Name="EnumContent" HorizontalAlignment="Left" Text="{Binding}" VerticalAlignment="Center" Margin="2,0" />

                            </DockPanel>                            
                        </Border>                        
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter TargetName="Content" Property="Text" Value="On"/>
                                <Setter TargetName="ForegroundPanel" Property="Background">
                                    <Setter.Value>
                                        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                            <GradientStop Color="Gray" Offset="0.0"/>
                                            <GradientStop Color="Green" Offset="0.5"/>
                                            <GradientStop Color="Gray" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                                <Setter TargetName="CheckFlag" Property="Background">
                                    <Setter.Value>
                                        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                            <GradientStop Color="WhiteSmoke" Offset="0.0"/>
                                            <GradientStop Color="Green" Offset="0.5"/>
                                            <GradientStop Color="WhiteSmoke" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                                <Setter TargetName="Content" Property="DockPanel.Dock" Value="Left"/>
                                <Setter TargetName="EnumContent" Property="DockPanel.Dock" Value="Left"/>
                                <Setter TargetName="CheckFlag" Property="DockPanel.Dock" Value="Right"/>
                            </Trigger>
                            <Trigger Property="IsChecked" Value="False">
                                <Setter TargetName="Content" Property="Text" Value="Off"/>
                                <Setter TargetName="ForegroundPanel" Property="Background">
                                    <Setter.Value>
                                        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                            <GradientStop Color="Gray" Offset="0.0"/>
                                            <GradientStop Color="Silver" Offset="0.5"/>
                                            <GradientStop Color="Gray" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                                <Setter TargetName="CheckFlag" Property="Background">
                                    <Setter.Value>
                                        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                            <GradientStop Color="WhiteSmoke" Offset="0.0"/>
                                            <GradientStop Color="Silver" Offset="0.5"/>
                                            <GradientStop Color="WhiteSmoke" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                                <Setter TargetName="EnumContent" Property="DockPanel.Dock" Value="Left"/>
                                <Setter TargetName="Content" Property="DockPanel.Dock" Value="Right"/>
                                <Setter TargetName="CheckFlag" Property="DockPanel.Dock" Value="Left"/>
                                
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>


        <ObjectDataProvider x:Key="enumDayOfWeek" MethodName="GetValues" ObjectType="{x:Type System:Enum}" >
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="local:DayOfWeek"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

        <local:FlagEnumConverter x:Key = "myconverter"/>
        <DataTemplate x:Key = "DataTemplate1">
            <local:FlagCheckBox x:Name="chkEnum" Content="{Binding}" Width="150" Style="{StaticResource HorizontalSlideCheckBoxStyle}">
                <local:FlagCheckBox.IsChecked>
                        <MultiBinding Converter = "{StaticResource myconverter}" Mode="TwoWay">
                            <Binding Path="DataContext.MultiValue" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}" Mode="OneWay"></Binding>
                             <Binding   ElementName="chkEnum" Path="Content" Mode="OneWay" />
                    </MultiBinding>
                </local:FlagCheckBox.IsChecked>
                <local:FlagCheckBox.MyContent>
                        <Binding Path="DataContext.MultiValue" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}" Mode="TwoWay"></Binding>

                </local:FlagCheckBox.MyContent>
            </local:FlagCheckBox>
             
        </DataTemplate>
        
    </Window.Resources>
    <Grid>
        <StackPanel>
            <Label Content="{Binding Path=MultiValue}" />
            <ListView Name = "LV_FilterList" Margin = "5" ItemsSource = "{Binding Source = {StaticResource enumDayOfWeek}}" ItemTemplate = "{DynamicResource DataTemplate1}"/>
        </StackPanel>
    </Grid>
</Window>
